package cn.iocoder.yudao.module.wine.controller.app.supplyfavorite;

import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import java.util.*;
import java.util.stream.Collectors;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.wine.controller.app.supplyfavorite.vo.*;
import cn.iocoder.yudao.module.wine.dal.dataobject.supplyfavorite.SupplyFavoriteDO;
import cn.iocoder.yudao.module.wine.service.supplyfavorite.SupplyFavoriteService;

@Tag(name = "用户 APP - 供求信息收藏")
@RestController
@RequestMapping("/wine/supply-favorite")
@Validated
public class AppSupplyFavoriteController {

    @Resource
    private SupplyFavoriteService supplyFavoriteService;

    @PostMapping("/create")
    @Operation(summary = "收藏供求信息")
    public CommonResult<Long> createSupplyFavorite(@Valid @RequestBody AppSupplyFavoriteSaveReqVO createReqVO) {
        return success(supplyFavoriteService.createSupplyFavorite(createReqVO));
    }

    @DeleteMapping("/delete")
    @Operation(summary = "取消收藏")
    @Parameter(name = "supplyInfoId", description = "编号", required = true)
    public CommonResult<Boolean> deleteSupplyFavorite(@RequestParam("supplyInfoId") Long supplyInfoId) {
        supplyFavoriteService.deleteSupplyFavoriteBySupplyInfoId(supplyInfoId);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得收藏的供求信息详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<AppSupplyFavoriteRespVO> getSupplyFavorite(@RequestParam("id") Long id) {
        SupplyFavoriteDO supplyFavorite = supplyFavoriteService.getSupplyFavorite(id);
        return success(BeanUtils.toBean(supplyFavorite, AppSupplyFavoriteRespVO.class));
    }

    @GetMapping("/list")
    @Operation(summary = "我的收藏信息列表")
    public CommonResult<List<AppSupplyFavoriteRespVO>> getSupplyFavoriteList(@Valid AppSupplyFavoritePageReqVO listReqVO) {
        List<AppSupplyFavoriteRespVO> list = supplyFavoriteService.getSupplyFavoriteList(listReqVO);
        List<AppSupplyFavoriteRespVO> collect = list.stream().peek(item -> {
            item.setUserAreaName(AreaUtils.format(item.getUserAreaId(), " "));
        }).collect(Collectors.toList());
        return success(collect);
    }


    @GetMapping("/image")
    @Operation(summary = "获得我收藏的图片")
    public CommonResult<List<AppImageVO>> getSupplyCollectImage() {
        List<AppImageVO> list = supplyFavoriteService.getSupplyFavoriteImage();
        return success(list);
    }
}



